package com.bilicraft.plugin.kexue.commands;

import java.io.File;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import com.bilicraft.plugin.kexue.ShellUser;

public class BiliCmdRename extends BiliCmd{
	public BiliCmdRename(){
		nofArgs = 2;
	}

	protected boolean doExec(CommandSender sender, Command cmd, String label, String[] args, ShellUser shellUser) {
		try{
			String cddir = shellUser.curdir+'/'+args[0];
			File fdir = new File(cddir);
			String ccdir = shellUser.curdir+'/'+args[1];
			File cdir = new File(ccdir);
			if(fdir.exists()){
				if(fdir.renameTo(cdir)){
					sender.sendMessage("File "+cddir+" rename to" + ccdir + ".");
				}else{
					sender.sendMessage("File "+cddir+" rename failed.");
				}
			}else{
				sender.sendMessage("Invalid path: "+cddir+".");
			}
			return true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
